package com.aspose.cells.b.a;

import com.aspose.cells.DateTime;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParsePosition;
import java.util.Date;

public final class ze {
   public static float a(Object var0) {
      if (var0 == null) {
         return 0.0F;
      } else if (!(var0 instanceof Byte) && !(var0 instanceof Integer) && !(var0 instanceof Short) && !(var0 instanceof Long)) {
         if (var0 instanceof Float) {
            return (float)((Float)var0).intValue();
         } else if (var0 instanceof Double) {
            if ((Double)var0 <= 3.4028234663852886E38D && (Double)var0 >= -3.4028234663852886E38D) {
               return ((Double)var0).floatValue();
            } else {
               throw new ClassCastException("Overflow in Double to float conversion. Double value: " + var0 + ".");
            }
         } else {
            float var1;
            if (var0 instanceof BigInteger) {
               var1 = ((BigInteger)var0).floatValue();
               if (var1 != Float.POSITIVE_INFINITY && var1 != Float.NEGATIVE_INFINITY) {
                  return var1;
               } else {
                  throw new ClassCastException("Overflow in BigInteger to float conversion. BigInteger value: " + var0 + ".");
               }
            } else if (var0 instanceof BigDecimal) {
               var1 = ((BigDecimal)var0).floatValue();
               if (var1 != Float.POSITIVE_INFINITY && var1 != Float.NEGATIVE_INFINITY) {
                  return var1;
               } else {
                  throw new ClassCastException("Overflow in BigInteger to float conversion. BigDecimal value: " + var0 + ".");
               }
            } else if (var0 instanceof String) {
               try {
                  return Float.parseFloat((String)var0);
               } catch (NumberFormatException var2) {
                  throw new ClassCastException("Overflow in String to float conversion. String value: " + var0 + ".");
               }
            } else if (var0 instanceof Character) {
               return (float)(Character)var0;
            } else {
               throw new ClassCastException("Can't convert to float value of type '" + var0.getClass().getName() + "'.");
            }
         }
      } else {
         return ((Number)var0).floatValue();
      }
   }

   public static long b(Object var0) {
      if (var0 == null) {
         return 0L;
      } else if (var0 instanceof Integer) {
         return ((Integer)var0).longValue();
      } else if (!(var0 instanceof Byte) && !(var0 instanceof Short)) {
         if (var0 instanceof Long) {
            return (long)((Long)var0).intValue();
         } else if (var0 instanceof Float) {
            if ((Float)var0 <= 9.223372E18F && (Float)var0 >= -9.223372E18F) {
               return ((Float)var0).longValue();
            } else {
               throw new ClassCastException("Overflow in Float to long conversion. Float value: " + var0 + ".");
            }
         } else if (var0 instanceof Double) {
            if ((Double)var0 <= 9.223372036854776E18D && (Double)var0 >= -9.223372036854776E18D) {
               return ((Double)var0).longValue();
            } else {
               throw new ClassCastException("Overflow in Double to long conversion. Double value: " + var0 + ".");
            }
         } else if (var0 instanceof BigDecimal) {
            try {
               return ((BigDecimal)var0).longValue();
            } catch (ArithmeticException var2) {
               throw new ClassCastException("Overflow in BigDecimal to long conversion. BigDecimal value: " + var0 + ".");
            }
         } else if (var0 instanceof BigInteger) {
            if (((BigInteger)var0).compareTo(BigInteger.valueOf(Long.MAX_VALUE)) != 1 && ((BigInteger)var0).compareTo(BigInteger.valueOf(Long.MIN_VALUE)) != -1) {
               return ((BigInteger)var0).longValue();
            } else {
               throw new ClassCastException("Overflow in BigInteger to long conversion. BigInteger value: " + var0 + ".");
            }
         } else if (var0 instanceof String) {
            try {
               return Long.parseLong((String)var0);
            } catch (NumberFormatException var3) {
               throw new ClassCastException("Overflow in String to long conversion. String value: " + var0 + ".");
            }
         } else if (var0 instanceof Boolean) {
            return (Boolean)var0 ? 1L : 0L;
         } else if (var0 instanceof Character) {
            return (long)(Character)var0;
         } else if (var0 instanceof Enum) {
            return (long)((Enum)var0).ordinal();
         } else {
            throw new ClassCastException("Can't convert to long value of type '" + var0.getClass().getName() + "'.");
         }
      } else {
         return ((Number)var0).longValue();
      }
   }

   public static long c(Object var0) {
      if (var0 == null) {
         return 0L;
      } else if (var0 instanceof Integer) {
         return ((Integer)var0).longValue();
      } else if (!(var0 instanceof Byte) && !(var0 instanceof Short)) {
         if (var0 instanceof Long) {
            return (Long)var0;
         } else if (var0 instanceof Float) {
            if ((Float)var0 <= 9.223372E18F && (Float)var0 >= -9.223372E18F) {
               return ((Float)var0).longValue();
            } else {
               throw new ClassCastException("Overflow in Float to long conversion. Float value: " + var0 + ".");
            }
         } else if (var0 instanceof Double) {
            if ((Double)var0 <= 9.223372036854776E18D && (Double)var0 >= -9.223372036854776E18D) {
               return ((Double)var0).longValue();
            } else {
               throw new ClassCastException("Overflow in Double to long conversion. Double value: " + var0 + ".");
            }
         } else if (var0 instanceof BigDecimal) {
            try {
               return ((BigDecimal)var0).longValue();
            } catch (ArithmeticException var2) {
               throw new ClassCastException("Overflow in BigDecimal to long conversion. BigDecimal value: " + var0 + ".");
            }
         } else if (var0 instanceof BigInteger) {
            if (((BigInteger)var0).compareTo(BigInteger.valueOf(Long.MAX_VALUE)) != 1 && ((BigInteger)var0).compareTo(BigInteger.valueOf(Long.MIN_VALUE)) != -1) {
               return ((BigInteger)var0).longValue();
            } else {
               throw new ClassCastException("Overflow in BigInteger to long conversion. BigInteger value: " + var0 + ".");
            }
         } else if (var0 instanceof String) {
            try {
               return Long.parseLong((String)var0);
            } catch (NumberFormatException var3) {
               throw new ClassCastException("Overflow in String to long conversion. String value: " + var0 + ".");
            }
         } else if (var0 instanceof Boolean) {
            return (Boolean)var0 ? 1L : 0L;
         } else if (var0 instanceof Character) {
            return (long)(Character)var0;
         } else if (var0 instanceof Enum) {
            return (long)((Enum)var0).ordinal();
         } else {
            throw new ClassCastException("Can't convert to long value of type '" + var0.getClass().getName() + "'.");
         }
      } else {
         return ((Number)var0).longValue();
      }
   }

   public static short d(Object var0) {
      if (var0 == null) {
         return 0;
      } else if (var0 instanceof Integer) {
         if ((Integer)var0 <= 32767 && (Integer)var0 >= -32768) {
            return ((Integer)var0).shortValue();
         } else {
            throw new ClassCastException("Overflow in int to short conversion. int value: " + var0 + ".");
         }
      } else if (!(var0 instanceof Byte) && !(var0 instanceof Short)) {
         if (var0 instanceof Long) {
            if ((Long)var0 <= 32767L && (Long)var0 >= -32768L) {
               return ((Long)var0).shortValue();
            } else {
               throw new ClassCastException("Overflow in long to short conversion. long value: " + var0 + ".");
            }
         } else if (var0 instanceof Float) {
            if ((Float)var0 <= 32767.0F && (Float)var0 >= -32768.0F) {
               return ((Float)var0).shortValue();
            } else {
               throw new ClassCastException("Overflow in Float to short conversion. Float value: " + var0 + ".");
            }
         } else if (var0 instanceof Double) {
            if ((Double)var0 <= 32767.0D && (Double)var0 >= -32768.0D) {
               return ((Double)var0).shortValue();
            } else {
               throw new ClassCastException("Overflow in Double to short conversion. Double value: " + var0 + ".");
            }
         } else if (var0 instanceof BigInteger) {
            if (((BigInteger)var0).compareTo(BigInteger.valueOf(32767L)) != 1 && ((BigInteger)var0).compareTo(BigInteger.valueOf(-32768L)) != -1) {
               return ((BigInteger)var0).shortValue();
            } else {
               throw new ClassCastException("Overflow in BigInteger to short conversion. BigInteger value: " + var0 + ".");
            }
         } else if (var0 instanceof String) {
            try {
               return Short.parseShort((String)var0);
            } catch (NumberFormatException var2) {
               throw new ClassCastException("Overflow in String to int conversion. String value: " + var0 + ".");
            }
         } else if (var0 instanceof Boolean) {
            return (short)((Boolean)var0 ? 1 : 0);
         } else if (var0 instanceof Character) {
            return (short)(Character)var0;
         } else {
            throw new ClassCastException("Can't convert to Short value of type '" + var0.getClass().getName() + "'.");
         }
      } else {
         return ((Number)var0).shortValue();
      }
   }

   public static long a(String var0, int var1) {
      return Long.parseLong(var0, var1);
   }

   public static String a(long var0, int var2) {
      return Long.toString(var0, var2);
   }

   public static String a(byte var0, int var1) {
      long var2 = (long)var0;
      if (var2 < 0L) {
         var2 += 256L;
      }

      return Long.toString(var2, var1);
   }

   public static String e(Object var0) {
      if (var0 == null) {
         return null;
      } else if (var0 instanceof String) {
         return (String)var0;
      } else if (var0 instanceof Byte) {
         return ((Byte)var0).toString();
      } else if (var0 instanceof Boolean) {
         return ((Boolean)var0).toString();
      } else if (var0 instanceof Short) {
         return ((Short)var0).toString();
      } else if (var0 instanceof Integer) {
         return ((Integer)var0).toString();
      } else if (var0 instanceof Long) {
         return ((Long)var0).toString();
      } else if (var0 instanceof Float) {
         return ((Float)var0).toString();
      } else {
         return var0 instanceof Double ? ((Double)var0).toString() : var0.toString();
      }
   }

   public static byte a(int var0) {
      if (var0 <= 127 && var0 >= -128) {
         return (byte)(var0 & 255);
      } else {
         throw new ClassCastException("Overflow in int to byte conversion. int value: " + Integer.toString(var0) + ".");
      }
   }

   public static char a(String var0) {
      if (var0 != null && var0.length() == 1) {
         return var0.charAt(0);
      } else {
         throw new ClassCastException("Overflow in String to Char conversion. String must be exactly one character long. String value: '" + var0 + "'.");
      }
   }

   public static int b(String var0, int var1) {
      return Integer.parseInt(var0, var1);
   }

   public static int f(Object var0) {
      if (var0 == null) {
         return 0;
      } else if (var0 instanceof Integer) {
         return (Integer)var0;
      } else if (!(var0 instanceof Byte) && !(var0 instanceof Short)) {
         if (var0 instanceof Long) {
            if ((Long)var0 <= 2147483647L && (Long)var0 >= -2147483648L) {
               return ((Long)var0).intValue();
            } else {
               throw new ClassCastException("Overflow in long to int conversion. long value: " + var0 + ".");
            }
         } else if (var0 instanceof Float) {
            if ((Float)var0 <= 2.14748365E9F && (Float)var0 >= -2.14748365E9F) {
               return ((Float)var0).intValue();
            } else {
               throw new ClassCastException("Overflow in Float to int conversion. Float value: " + var0 + ".");
            }
         } else if (var0 instanceof Double) {
            if ((Double)var0 <= 2.147483647E9D && (Double)var0 >= -2.147483648E9D) {
               return ((Double)var0).intValue();
            } else {
               throw new ClassCastException("Overflow in Double to int conversion. Double value: " + var0 + ".");
            }
         } else if (var0 instanceof BigInteger) {
            if (((BigInteger)var0).compareTo(BigInteger.valueOf(2147483647L)) != 1 && ((BigInteger)var0).compareTo(BigInteger.valueOf(-2147483648L)) != -1) {
               return ((BigInteger)var0).intValue();
            } else {
               throw new ClassCastException("Overflow in BigInteger to int conversion. BigInteger value: " + var0 + ".");
            }
         } else if (var0 instanceof String) {
            try {
               String var1 = (String)var0;
               if (var1.startsWith("+")) {
                  var1 = var1.substring(1);
               }

               return Integer.parseInt(var1);
            } catch (NumberFormatException var2) {
               throw new ClassCastException("Overflow in String to int conversion. String value: " + var0 + ".");
            }
         } else if (var0 instanceof Boolean) {
            return (Boolean)var0 ? 1 : 0;
         } else if (var0 instanceof Character) {
            return (Character)var0;
         } else if (var0 instanceof Enum) {
            return ((Enum)var0).ordinal();
         } else {
            throw new ClassCastException("Can't convert to Integer value of type '" + var0.getClass().getName() + "'.");
         }
      } else {
         return ((Number)var0).intValue();
      }
   }

   public static double g(Object var0) {
      if (var0 == null) {
         return 0.0D;
      } else if (var0 instanceof Double) {
         return (Double)var0;
      } else {
         double var4;
         if (var0 instanceof BigDecimal) {
            var4 = ((BigDecimal)var0).doubleValue();
            if (var4 != Double.POSITIVE_INFINITY && var4 != Double.NEGATIVE_INFINITY) {
               return var4;
            } else {
               throw new ClassCastException("Overflow in BigDecimal to double conversion. BigDecimal value: " + var0 + ".");
            }
         } else if (var0 instanceof BigInteger) {
            var4 = ((BigInteger)var0).doubleValue();
            if (var4 != Double.POSITIVE_INFINITY && var4 != Double.NEGATIVE_INFINITY) {
               return var4;
            } else {
               throw new ClassCastException("Overflow in BigInteger to double conversion. BigInteger value: " + var0 + ".");
            }
         } else if (var0 instanceof Number) {
            return ((Number)var0).doubleValue();
         } else if (var0 instanceof String) {
            String var1 = c(((String)var0).trim());
            ParsePosition var2 = new ParsePosition(0);
            Number var3 = com.aspose.cells.a.a.zb.d.parse(var1, var2);
            if (var2.getIndex() < var1.length()) {
               throw new NumberFormatException("Input string was not in a correct format: " + var1);
            } else {
               return var3.doubleValue();
            }
         } else if (var0 instanceof Boolean) {
            return (Boolean)var0 ? 1.0D : 0.0D;
         } else if (var0 instanceof Enum) {
            return (double)((Enum)var0).ordinal();
         } else {
            throw new ClassCastException("Can't convert to Double value of type '" + var0.getClass().getName() + "'.");
         }
      }
   }

   private static String c(String var0) {
      var0 = var0.replace('e', 'E');
      int var1 = var0.indexOf(69);
      if (var1 > 0) {
         ++var1;
         if (var0.length() > var1 && var0.charAt(var1) == '+') {
            var0 = var0.substring(0, var1) + var0.substring(var1 + 1);
         }
      }

      return var0;
   }

   public static DateTime h(Object var0) throws Exception {
      if (var0 == null) {
         return DateTime.a;
      } else if (var0 instanceof DateTime) {
         return (DateTime)var0;
      } else if (var0 instanceof Date) {
         return new DateTime((Date)var0);
      } else if (var0 instanceof Long) {
         return new DateTime((Long)var0);
      } else if (var0 instanceof String) {
         return DateTime.a((String)var0);
      } else {
         throw new ClassCastException("Can't convert to DateTime value of type '" + var0.getClass().getName() + "'.");
      }
   }

   public static byte[] b(String var0) {
      return zb.a(var0);
   }

   public static String a(byte[] var0) {
      if (var0 == null) {
         throw new NullPointerException("inArray");
      } else {
         return a(var0, 0, var0.length);
      }
   }

   public static String a(byte[] var0, int var1, int var2) {
      if (var0 == null) {
         throw new NullPointerException("inArray");
      } else if (var1 >= 0 && var1 <= var0.length) {
         if (var2 >= 0 && var2 <= var0.length - var1) {
            int var3 = (int)(((long)var2 + 2L) * 4L / 3L);
            StringBuilder var4 = new StringBuilder(var3);
            int var5 = 0;
            int var6 = 0;
            String var7 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
            int var8 = var2;

            while(var8 > 0) {
               var5 = (var5 << 8) + (var0[var1++] & 255);
               var6 += 8;
               --var8;

               while(var6 >= 6) {
                  var6 -= 6;
                  var4.append(var7.charAt(var5 >> var6));
                  var5 &= (1 << var6) - 1;
               }
            }

            var2 %= 3;
            if (var2 == 1) {
               var4.append(var7.charAt(var5 << 6 - var6));
               var4.append('=');
               var4.append('=');
            } else if (var2 == 2) {
               var4.append(var7.charAt(var5 << 6 - var6));
               var4.append('=');
            }

            return var4.toString();
         } else {
            throw new IndexOutOfBoundsException("length");
         }
      } else {
         throw new IndexOutOfBoundsException("offset");
      }
   }
}
